
<?php if (!isset($user)){?>
Login: <input id="login_login" class="textinput" type="text" />	
Password: <input id="login_password" class="textinput" type="password" />
<button class="myButton" id="login_button">Submit</button>

<script type="text/javascript">
$(function(){
	$("#login_login").playerSearch();

	var do_login = function()
	{
		var resp = $("#login_login").data("resp");
		var reloc = function(){
			window.location.href = "admin.php";
		};
		if (resp != null){
			var login_id = resp.player_id;
			var password = $("#login_password").val();

			if (password != "")
			{
				$.post("admin.php", {
					"login_id": login_id,
					"password" : password 
				}, function(msg)
				{
					if (msg != "ok")
					{
						message(msg, "Error", reloc);
					}
					else
					{
						reloc();
					}
				});
			}
		}
	};
	
	$("#login_password").keypress(function(e){
		if (e.keyCode==13){
			do_login();
		}
	});
	$("#login_button").click(do_login);
	
});
</script>

<?php }else{?>

Hello, <?php echo $user->name?>!
<button class="myButton" id="admin_home">Admin</button>
<button class="myButton" id="edit_profile">Edit profile</button>
<button class="myButton" id="logout">Logout</button>
<script type="text/javascript">
$(function(){
	$("#logout").click(function(){
		var reloc = function(){
			window.location.href = "admin.php";
		};
		$.post("admin.php", {"logout" : "1"}, function(msg)
		{
			if (msg != "ok")
			{
				message(msg, "Error", reloc);
			}
			else
			{
				reloc();
			}
		});
	});

	$("#edit_profile").click(function(){
		ajaxAdmin("edit_profile", {cacheable : true});
	});

	$("#admin_home").click(function(){
		window.location.href = "admin.php";
	});
	
});
</script>

<?php }//if?>
